﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Controls.DataVisualization.Charting;
using LuyenThiVer03.UserData;

namespace LuyenThiVer03
{
    public partial class PageKetQua : PhoneApplicationPage
    {
        public PageKetQua()
        {
            InitializeComponent();
            LoadChartLy();
            LoadChartHoa();
            LoadChartAnh();
            LoadChartSinh();
        }

        private List<BieuDo> loadData(string mon)
        {
            List<BieuDo> listBieuDo = new List<BieuDo>(7);
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = " " });
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = " " });
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = "  " });
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = "  " });
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = "  " });
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = "  " });
            listBieuDo.Add(new BieuDo() { Score = 0, DeSo = " " });

            List<BieuDo> listB = BieuDo.loadScore(mon);

            if (listB.Count == 0)
            {
                return null;
            }

            for (int i = 0; i < listB.Count; i++)
            {
                BieuDo b = listB[i];
                listBieuDo[i] = b;
            }

                return listBieuDo;         
        }


        private void LoadChartLy()
        {
            ColumnSeries series = new ColumnSeries();
            chrLy.Series.Add(series);
            series.SetBinding(ColumnSeries.ItemsSourceProperty,
                                new System.Windows.Data.Binding());
            series.ItemsSource = this.loadData("Lý");
            series.DependentValuePath = "Score";
            series.IndependentValuePath = "DeSo";
        }

        private void LoadChartHoa()
        {
            ColumnSeries series = new ColumnSeries();
            chrHoa.Series.Add(series);
            

            series.SetBinding(ColumnSeries.ItemsSourceProperty,
                                new System.Windows.Data.Binding());
            series.ItemsSource = this.loadData("Hóa");
            series.DependentValuePath = "Score";
            series.IndependentValuePath = "DeSo";
        }

        private void LoadChartAnh()
        {
            ColumnSeries series = new ColumnSeries();
            chrAnh.Series.Add(series);
            series.SetBinding(ColumnSeries.ItemsSourceProperty,
                                new System.Windows.Data.Binding());
            series.ItemsSource = this.loadData("Anh");
            series.DependentValuePath = "Score";
            series.IndependentValuePath = "DeSo";
        }

        private void LoadChartSinh()
        {
            ColumnSeries series = new ColumnSeries();
            chrSinh.Series.Add(series);
            series.SetBinding(ColumnSeries.ItemsSourceProperty,
                                new System.Windows.Data.Binding());
            series.ItemsSource = this.loadData("Sinh");
            series.DependentValuePath = "Score";
            series.IndependentValuePath = "DeSo";
        }
    }
}